package com.sxsihe.heartmate;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.daimajia.numberprogressbar.NumberProgressBar;
import com.sxsihe.heartmate.util.HttpMultipartPost;
import com.sxsihe.heartmate.util.SharePreferenceUtil;

/**
 * Created by mac on 16/9/13.
 */
public class DiagnoseActiviy2  extends Activity {
    TextView result_text;
    ImageView back_icon;
    SharePreferenceUtil spu;
    int age;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.diagnostic_results);
        if (spu == null) {
            spu = SharePreferenceUtil.getInstance(this);
        }
        age = Integer.parseInt(spu.get("age","18"));
        String type = getIntent().getExtras().getString("type");
        int heartrate = Integer.parseInt(getIntent().getExtras().getString("heartrate"));
        int heartage = Integer.parseInt(getIntent().getExtras().getString("heart_age"));
                ((TextView) findViewById(R.id.heart_age)).setText(getIntent().getExtras().getString("heart_age"));
        ((TextView)findViewById(R.id.heart_count)).setText(getIntent().getExtras().getString("heart_count"));
        ((TextView)findViewById(R.id.r2r)).setText(getIntent().getExtras().getString("r2r"));
        ((TextView)findViewById(R.id.mood)).setText(getIntent().getExtras().getString("mood"));
        ((TextView)findViewById(R.id.stress)).setText(getIntent().getExtras().getString("stress"));
        ((TextView)findViewById(R.id.signal)).setText(getIntent().getExtras().getString("signal"));
        ((TextView)findViewById(R.id.d_heartrate)).setText(getIntent().getExtras().getString("heartrate"));
        ((TextView)findViewById(R.id.__heart_rate)).setText("        "+getIntent().getExtras().getString("heartrate"));
        ((TextView)findViewById(R.id.duration)).setText(getIntent().getExtras().getString("duration")+"秒");
        back_icon = (ImageView) findViewById(R.id.back_icon);
        back_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DiagnoseActiviy2.this.finish();
            }
        });
        ImageView icon = (ImageView) findViewById(R.id.diagnostic_heart);
        RelativeLayout icon_layout = (RelativeLayout)findViewById(R.id.icon_layout);
        icon_layout.measure(0, 0);
        icon.measure(0, 0);
        int width = icon_layout.getMeasuredWidth();
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) icon.getLayoutParams();
        params.leftMargin = (int) (heartrate / 160.0 * width) - icon.getWidth() / 2;
        icon.setLayoutParams(params);

        result_text = (TextView)findViewById(R.id.result_text);


        if("serial".equals(type)||getIntent().getExtras().getString("heart_age")==null||getIntent().getExtras().getString("heart_age").equals("")){
            ((View)findViewById(R.id.heart_age_bar)).setVisibility(View.GONE);
            ((View)findViewById(R.id.heart_age_layout)).setVisibility(View.GONE);
            ((View)findViewById(R.id.heart_count_bar)).setVisibility(View.GONE);
            ((View)findViewById(R.id.heart_count_layout)).setVisibility(View.GONE);
            ((View)findViewById(R.id.stress_bar)).setVisibility(View.GONE);
            ((View)findViewById(R.id.stress_layout)).setVisibility(View.GONE);
            ((View)findViewById(R.id.mood_bar)).setVisibility(View.GONE);
            ((View)findViewById(R.id.mood_layout)).setVisibility(View.GONE);
            ((View)findViewById(R.id.r2r_bar)).setVisibility(View.GONE);
            ((View)findViewById(R.id.r2r_layout)).setVisibility(View.GONE);
            System.out.println("heartrate:"+heartrate);
            if(heartrate<60){
                result_text.setText("心动过缓，建议注意休息和少吃辛辣刺激食物，避免着凉，避免刺激，定期体检。");
            } if(heartrate>=60&&heartrate<100){
                result_text.setText("心率正常，多吃水果，坚持做适量运动，保持平和积极的心态。");

            } if(heartrate>=100){

                result_text.setText("心动过速，建议静息时多次自测心率，如果持续性心率在这个范围，建议及时就诊。");
            }
        }else{
            String tmp = "";
            if(age<heartage){
                tmp = "比你的实际年龄大"+(heartage-age)+"岁";
            }
            else if (age>heartage){
                tmp = "比你的实际年龄小"+(age-heartage)+"岁";
            }
            else if (age==heartage){
                tmp = "与你的实际年龄相符";
            }

            if(heartage==0){
                result_text.setText("你的心脏年龄是"+heartage+"岁,这可能是一次不正常的记录。");
            }
            else if(heartage<=25){

                result_text.setText("你的心脏年龄是"+heartage+"岁,"+tmp+"。你年轻的心脏年龄让你精力充沛,积\n" +
                        "极思考,它有助于你处理高要求的工作和运动。年轻的心脏同时也需要照顾。建议您\n" +
                        "避免熬夜深夜,做适量的运动,保持一个和平积极的心态。你还应多吃新鲜水果和蔬菜,\n" +
                        "减少高脂肪食物的摄入来保持你的状态。");
            }else  if(25<heartage && heartage<=39){
                result_text.setText("你的心脏年龄是"+heartage+"岁,"+tmp+"。你有一颗成熟的心脏。在紧张的工作环境里,请不要忘了保证足够的睡眠和锻炼,吃好,照顾好自己。");
            }else  if(40<=heartage && heartage<=55){
                result_text.setText("你的心脏年龄是"+heartage+"岁,"+tmp+"。请密切关注您的心脏健康并合理安排你的工作和生活以此来减轻心脏的负担。建议你多吃对心脏有益的食物,如鱼类、全麦、豆类、坚果、蔬菜、红酒和绿茶。你也应当保证一定的运动量来强化你的心脏。");
            }else  if(56<=heartage && heartage<=70){
                result_text.setText("你的心脏年龄是"+heartage+"岁,"+tmp+"。你的心脏功能正在向老年前进。建议您讲究生活纪律,避免变得过于兴奋或紧张。你也应该定期体检和进食更多对你的心脏有益的食物,如鱼类、粗粮、豆类、坚果、蔬菜、红酒和绿茶。同样重要的是你也应当保证适当的运动量让你的心脏有效工作。");
            }else  if(heartage>70){
                result_text.setText("你的心脏年龄是"+heartage+"岁,"+tmp+"。建议您定期去医院体检查,仔细按照医生的指示来预防或治疗心脏病。你也需要适量的运动,保持和平的心态。讲究生活纪律和健康饮食可以改善心血管系统的功能,防止心脏病。");
            }
        }

    }
}
